<?php

namespace App\HttpController\Admin;

use App\Component\Excel;
use App\Core\Output;
use App\Core\OutputTrait;
use App\Logic\Member\MemberService;
use App\Logic\Order\OrderService;
use App\Logic\UploadService;
use EasySwoole\Http\Message\Status;
use EasySwoole\HttpAnnotation\AnnotationTag\Api;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiDescription;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiGroup;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiSuccessParam;
use EasySwoole\HttpAnnotation\AnnotationTag\Method;
use EasySwoole\HttpAnnotation\AnnotationTag\Param;

/**
 * @ApiGroup(groupName="公共模块")

 */
class Common extends BaseController{

    public function memberDict(){
        $service = new MemberService();
        $result = $service->getDict($this->request());
        return $this->writeJsonByOutput($result);
    }

    public function upload(){
        //获取图片
        $request = $this->request();
        $file = $request->getUploadedFile('file');

        $uploadImg = new UploadService();
        $path = $uploadImg->upload($file);

        return $this->writeJsonByOutput($path);
    }
    function import(){
        //以下导入文件demo
        $file = $this->request()->getUploadedFile('file');
        $excel = new Excel();
        $data = $excel->import($file->getTempName());
//        var_dump($data);
        $data = (new Output())->setStatusCode(Status::CODE_OK)->setMsg('$message')->setData($data);
        return $this->writeJsonByOutput($data);
    }

}
